package com.TLLT.QADMobileItemEnquiry2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.Html;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class HelpDialog extends DialogFragment {

	private static Context mContext = null;

	public HelpDialog(Context context) {
		
		super();
		mContext = context;
		setStyle(STYLE_NO_TITLE, R.style.AppTheme);
	}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_help, container);
        TextView tv = (TextView) view.findViewById(R.id.help_text);
		tv.setText(Html.fromHtml(readRawTextFile(R.raw.help)));
		tv.setLinkTextColor(Color.BLUE);
		Linkify.addLinks(tv, Linkify.WEB_URLS);
				
        return view;
    }
    
    public static String readRawTextFile(int id) {
		InputStream inputStream = mContext.getResources().openRawResource(id);
		InputStreamReader in = new InputStreamReader(inputStream);
		BufferedReader buf = new BufferedReader(in);
		String line;
		StringBuilder text = new StringBuilder();
		try {

			while ((line = buf.readLine()) != null)
				text.append(line);
		} catch (IOException e) {
			return null;
		}
		return text.toString();
	}
}

 

